import collections
class Solution(object):
    def numSmallerByFrequency(self, queries, words):
        def f(s):
            d = collections.Counter(s)
            t = min(d.keys())
            return d[t]
        out = [0] * 10
        for word in words:
            out[f(word) - 1] += 1
        n = len(words)
        for i in range(1, 10):
            out[i] += out[i - 1]
        m = len(queries)
        ans = [0] * m
        for index, s in enumerate(queries):
            c = f(s)
            ans[index] = n - out[c - 1]
        return ans
